package com.facemox.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.facemox.controller.ModuleController;

@WebFilter(urlPatterns = "/*",filterName = "loginFilter")
public class LoginFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req =  (HttpServletRequest)request;
        HttpServletResponse resp =  (HttpServletResponse)response;
        
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if(username=="root" && password=="root") {
            //req.getSession().setAttribute(username, UUID.randomUUID());
            chain.doFilter(req, resp);
            //ModuleController.class.newInstance().getProjectList(modelMap);
        }else {
            // System.out.println("username:"+username+"password:"+password);
            request.getRequestDispatcher("/login.html").forward(req, resp);
        }
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
    
}
